<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
UserBean user = (UserBean)request.getSession().getAttribute("userBean");

String _db = user.getDbType();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.plugins.dictionary.DictionaryAction";
_jsonObj.methodname = "queryPage";
_jsonObj.logicdata = "[{\"types\":\"init\",\"pid\":\"\"}]";


var _jsonObj1 = {
	classname : "com.wxtf.platform.plugins.dictionary.DictionaryAction",
	methodname : "queryP"
};

var win = null;
var managerp = null;//左侧表格
var manager = null;//右侧表格

$(function(){
	managerp = $("#dicp-grid").ligerGrid({
		title:'父字典项',url: _url, parms: _jsonObj1, width: '100%', height: '100%',
		usePager: true, rownumbers: true, checkbox: true,alternatingRow: true,
		columns: [
			{ display: '字典类型', name: 'tmgd_type',width:100,align:'left' },
			{ display: '父字典项', name: 'tmgd_description',width:200,align:'left' }
		],
        onClickRows: function (data, rowindex, rowobj){
			_jsonObj.logicdata = '[{\"types\":\"serch1\",\"pid\":\"' + data.tmgd_type + '\"}]';
			manager.loadData();
    	},
    	onCheckRow: function(checked, rowdata, rowindex) {
   	       for (var rowid in this.records)
   	           this.unselect(rowid); 
   	       this.select(rowindex);
   	   }
	});
	manager = $("#dic-grid").ligerGrid({
		title:'子字典项',url: _url, parms: _jsonObj,width: '100%', height: '100%',
		usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,
		columns: [
			{ display: 'tmgd_id', name: 'tmgd_id', hide: true,width:1 },
			{ display: '字典名称', name: 'tmgd_name',width:300,align:'left' },
			{ display: '排序号', name: 'tmgd_order_num',width:60,align:'left' },
			{ display: '是否可用', name: 'tmgd_is_valid',width:60,align:'left',
				render: function(record, index, value, oth){ return value == '1'?'是':'否'; }
			},
			{ display: '编辑', name:'edit',width:60,render: function(record, index, value, oth){
					return "<img src='ligerUI/skins/icons/edit.gif' onclick='addData(" + JSON.stringify(record) + ")'></img>";
				}
			}
		],
		toolbar: {
			items: [
				{ text: '新建', click: function(){ addData(); }, icon: 'add' },
				{ line: true },
				{ text: '删除', click: function(){ delData(); },icon: 'delete'}
			]
		}
	});
});

/*
 * 新增/修改字典
 */
function addData(row){
	var row1 = managerp.getSelectedRow();
	if(!row1){
		warningTip("请选择一条父字典项");
		return;
	}
	document.getElementById('edit-form').reset();
	if(row){
		loadForm("edit-form", row);
	} else {
		$("#tmgd_id").val('');
		$("#tmgd_type").val(row1.tmgd_type);
		$("#tmgd_description").val(row1.tmgd_description);
	}
	
	if(win == null){
		win = initWindowByDiv('editDiv', '编辑字典', 600, 200 ,save, closeWin);
	}else{
		win.show();
	}
}

/*
 * 新建/修改字典信息
 */
function save(){
	var tmgd_name = $("#tmgd_name").val();
	var tmgd_order_num = $("#tmgd_order_num").val();
	var tmgd_memo = $("#tmgd_memo").val();

	if('' == tmgd_name){warningTip("字典名称：不能为空"); return;}
	if(!checkIsString(tmgd_name)){
		warningTip("字典名称：必须为字母、数字、下划线、中文组成");
		return;
	}
	if(fucCheckLength(tmgd_name) > 64){
		warningTip("字典名称：不能超过64字符");
		return;
	}
	if('' == tmgd_order_num){warningTip("排序号：不能为空"); return;}
	if(!isNum(tmgd_order_num)){
		warningTip("排序号：必须为整数");
		return;
	}
	if(-99999 > parseInt(tmgd_order_num) || parseInt(tmgd_order_num) > 99999){
		warningTip("排序号：必须在-99999~99999之间");
		return;
	}

	if(!checkIsString(tmgd_memo)){
		warningTip("备注：必须为字母、数字、下划线、中文组成");
		return;
	}
	if(fucCheckLength(tmgd_memo) > 512){
		warningTip("备注：不能超过512字符");
		return;
	}
	
	_jsonObj.logicdata = getForm("edit-form");
	var pkid = $("#tmgd_id").val();
	if(pkid == ''){
		_jsonObj.methodname = "save";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	} else {
		_jsonObj.methodname = "update";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	}
	
}

/*
 * 删除字典
 */
function delData(){
	var userIds = getUserIds();
	if(userIds == ""){
		warningTip('请至少选择一个字典项进行操作');
		return;
	}
	$.ligerDialog.confirm('确定要删除选中的数据吗？（删除不可恢复）', function (opt) { 			
		if(opt){
			_jsonObj.methodname = "delete";
			_jsonObj.logicdata = "[{\"ids\":\"" + userIds + "\"}]";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		}
	});
}

function getUserIds(){
	var arrayUsers = manager.getSelecteds();
	if(arrayUsers.length == 0){
		return "";
	} else {
		var text = "";
		for(var i=0; i<arrayUsers.length; i++){
			text += arrayUsers[i].tmgd_id + ",";
		}
		return text.substring(0, text.length - 1);
	}
}

/*
 * 条件查询
 */
function serch1(){
	var row = managerp.getSelectedRow();
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = '[{\"types\":\"serch1\",\"pid\":\"' + row.tmgd_type + '\"}]';
	manager.loadData();
}

/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	serch1();
	if(data.result || data.result == 'true'){
		succMsgTip(data.resultrecord);
	}else{
		warningTip(data.resultrecord);
	}
	if(win && data.result){
		win.hide();
	}
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	warningTip(data.resultrecord);
}
</script>
	</head>
	<body>
		<table>
			<tr>
				<td style=" width: 150px;"><div id="dicp-grid"></div></td>
				<td style=" width: 700px;"><div id="dic-grid"></div></td>
			</tr>	
		</table>
		<div id="editDiv">
			<form id="edit-form" name="edit-form">
				<input type="hidden" id="tmgd_id" name="tmgd_id" value="" />
				<input type="hidden" id="tmgd_code" name="tmgd_code" value="" />
				<input type="hidden" id="reserve1" name="reserve1" value="" />
				<input type="hidden" id="reserve2" name="reserve2" value="" />
				<input type="hidden" id="reserve3" name="reserve3" value="" />
				<input type="hidden" id="reserve4" name="reserve4" value="" />
				<input type="hidden" id="reserve5" name="reserve5" value="" />
				<input type="hidden" id="create_by" name="create_by" value="" />
				<input type="hidden" id="create_time" name="create_time" value="" />
				<input type="hidden" id="last_modify_by" name="last_modify_by" value="" />
				<input type="hidden" id="last_modify_time" name="last_modify_time" value="" />
				
				<table class="form_table">
					<tr>
						<td class="form_label">字典类型：</td>
						<td><input class="textbg1" id="tmgd_type" name="tmgd_type" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
						<td><font color="red"></font></td>
						<td class="form_label">字典描述：</td>
						<td><input class="textbg1" id="tmgd_description" name="tmgd_description" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td><font color="red"></font></td>
					</tr>
					<tr>
						<td class="form_label">字典名称：</td>
						<td><input class="textbg1" id="tmgd_name" name="tmgd_name" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td><font color="red">*</font></td>
						<td class="form_label">字典排序：</td>
						<td><input class="textbg1" id="tmgd_order_num" name="tmgd_order_num" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">是否有效：</td>
						<td>
							<select id="tmgd_is_valid" name="tmgd_is_valid" style=" width: 182px;">
								<option value="1">是</option>
								<option value="0">否</option>
							</select>
						</td>
						<td></td>
						<td class="form_label">备注：</td>
						<td><input class="textbg1" id="tmgd_memo" name="tmgd_memo" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
				</table>
			</form>
		</div>
		
		
	</body>
</html>




